<?php
/**
 * Building Model for Room Booking Component
 * 
 * @version 1.0
 * @package    Joomla
 * @subpackage RoomBooking
 * @copyright (C) 2011 Giovanni Marzulli
 * @license		GNU/GPL
 */
 
// No direct access
 
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport( 'joomla.application.component.model' );
 
class RoomBookingModelBuilding extends JModel
{
        
    /**
	 * Method to get Building name
	 * @return	string
	 */
	function getBuildName($id_building)
    {
		$db =& JFactory::getDBO();
 
  		$query = 'SELECT  name FROM #__roombooking_buildings WHERE id='.$id_building;
		$db->setQuery( $query );
   		$build = $db->loadObject();
   		
   		return $build->name;
    	
    }
    
    /**
	 * Method to get building opening and closing time
	 * @return object with data
	 */
    function getBuildOpenCloseTime($id){
		//inserire i controlli di esecuzione query e i relativi messaggi di errore con getErrorMsg
		$query = 'SELECT date_format( opening, "%H:%i" ) as opening, date_format( closing, "%H:%i" ) as closing  FROM #__roombooking_buildings WHERE id = '.$id;
		$this->_db->setQuery( $query );
		$this->_db->query();
		$times = $this->_db->loadObject();
		return $times;	
		
    }
    
    /**
	 * Method to get weekend opening
	 * @return boolean
	 */	
	function getWEOpening($id){
		//inserire i controlli di esecuzione query e i relativi messaggi di errore con getErrorMsg
		$query = 'SELECT we_opening  FROM #__roombooking_buildings WHERE id = '.$id;
		$this->_db->setQuery( $query );
		$this->_db->query();
		$we_opening = $this->_db->loadObject();
		
		return $we_opening->we_opening;	
    }
}
